package com.kye.express.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;

/**
 * Intent工具类
 * <p>
 * Created by SkyYu on 29/01/2018 15:47
 */
public class IntentUtil {

    private static final String TAG = "IntentUtil";

    private IntentUtil() {
    }

    /**
     * 传递多个参数进行页面跳转
     */
    public static void showIntent(Class<?> clzz, String[] keys, String[] values) {
        Activity currentActivity = ActivityManager.getInstance().getCurrentActivity();
        Intent intent = new Intent(currentActivity, clzz);
        if (values != null && values.length > 0) {
            for (int i = 0; i < values.length; i++) {
                if (!TextUtils.isEmpty(keys[i]) && !TextUtils.isEmpty(values[i])) {
                    intent.putExtra(keys[i], values[i]);
                }
            }
        }
        currentActivity.startActivity(intent);
    }

    /**
     * 传递一个参数进行页面跳转
     */
    public static void showIntent(Class<?> clzz, String key, String value) {
        Activity currentActivity = ActivityManager.getInstance().getCurrentActivity();
        Intent intent = new Intent(currentActivity, clzz);
        intent.putExtra(key, value);
        currentActivity.startActivity(intent);
    }

    /**
     * 打电话
     *
     * @param context
     * @param phoneNum
     */
    public static void call(Context context, String phoneNum) {
        Intent intent = new Intent();
        // 启动电话程序
        intent.setAction(Intent.ACTION_CALL);
        intent.setData(Uri.parse("tel://" + phoneNum));
        context.startActivity(intent);
    }
}
